<?php
/**
 * Created by JiangJiaCai.
 * User: Administrator
 * Date: 2017/9/22 0022
 * Time: 16:20
 */

namespace ext\service;


use App\Models\QdcsArticle;
use com_jjcbs\lib\Service;
use com_jjcbs\lib\ServiceFactory;
use ext\dao\ArticleDaoImpl;

class ArticleServiceImpl extends Service
{
    public $articleDao = null;

    public function __construct()
    {
        $this->articleDao = new ArticleDaoImpl();
    }

    public function exec()
    {
        // TODO: Implement exec() method.
    }

    /**
     * 获取最新一条头条信息
     * @return QdcsArticle
     */
    public function getOneTop(){
        return $this->articleDao->getList(QdcsArticle::class , 1 , ['is_top' => 1] ,'created_at' , 'desc');
    }

    public function getPos(QdcsArticle $article) : string {
        $classService = ServiceFactory::getInstance(ClassServiceImpl::class);
        return $classService->getClassPath($article->cls_id , ' > ') . ' > ' . $article->title;
    }

    public function getAbout(QdcsArticle $article) : array {
        $res =  $this->articleDao->getList(QdcsArticle::class , 12 , [
            ['cls_id' , '=' ,$article->cls_id],
            ['id' , '<>' , $article->id]

        ])->toArray();
        return [
            'left' => array_splice($res , 0 , 6),
            'right' => array_splice($res , 5 , 6)
        ];
    }

    public function getPageListByCls(int $cls_id){
        return $this->articleDao->getPageList(QdcsArticle::class , 15 , [
            'cls_id' => $cls_id
        ]);
    }

    public function getHotListPage(){
        return $this->articleDao->getPageList(QdcsArticle::class , 15 , [
            'is_hot' => 1
        ]);
    }

}